"""
Created on 2022-05-26
@author:刘飞
@description:入参、出参的各个字段的类型进行定义
按照顺序写【基类，出参，入参】
"""
from typing import Optional
from pydantic import BaseModel, Field


# 响应基类
class BaseOut(BaseModel):
    err: int = Field(0, title='响应码')
    msg: str = Field('ok', title='响应码说明')
    data: dict = Field({}, title='响应内容')


# 用户基类
class BaseUser(BaseModel):
    username: str = Field(..., title='用户名')
    email: Optional[str] = Field(None, title='邮箱')
    is_active: Optional[bool] = Field(True, title='是否激活')

    class Config:
        orm_mode = True
        schema_extra = {
            "example": {
                "username": "里斯",
                "email": "liufei-love@foxmail.com",
                "is_active": True
            }
        }


# 用户信息
class UserInfo(BaseUser):
    id: int = Field(None, title='用户id')

    class Config:
        orm_mode = True


# 创建用户入参
class UserIn(BaseUser):
    password: str = Field(..., title='密码')

    class Config:
        schema_extra = {
            "example": {
                "username": "admin",
                "password": "admin123",
                "is_active": True
            }
        }


# 用户信息响应
class InfoOut(BaseOut):
    data: Optional[UserInfo] = Field(None, title='响应内容')


# Token出参形式【也是登录返回形式】
class TokenOut(BaseModel):
    access_token: str = Field(None, title='token')
    token_type: str = Field(None, title='验证类型')
